<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>已买到宝贝</title>
    <script src="js/jquery-3.1.0.js"></script> 
    <script type="text/javascript">
    $(document).ready(function(){
    	$(".hideinfo").hide();
        $(".div_content:gt(0)").css("display","none");
        $(".navigation>li").click(function(){
            $(".navigation>li").removeClass("active");
            $(this).addClass("active");
            if($(this).html()=="所有订单"){
                $(".div_content").css("display","none");
                $(".div_content:eq(0)").css("display","block");
            }else  if($(this).html()=="买到的宝贝"){
                $(".div_content").css("display","none");
                $(".div_content:eq(1)").css("display","block");
            }else  if($(this).html()=="卖出的宝贝"){
                $(".div_content").css("display","none");
                $(".div_content:eq(2)").css("display","block");
            }
        });
        
        $(".active").click(function(){
        	window.location.reload();
        });
        
        //获取付款id
        var orderId;
        var doc;
        $(".fukuan").click(function(){
        	$(".hideinfo").show();
        	orderId=$(this).attr("orderId");
        	doc=$(this);
  	  });
        //隐藏付款框
        $("#bt2").click(function(){
   			$(".hideinfo").hide();
   		});  
        //验证密码和余额
       $("#bt1").click(function(){
	 		var s=$(".tab_sfk:eq(1) p").html();
	 		s=s.split("￥")[1];
	 		var password=$("#pay").val();
	 		if(confirm("确认付款?")){
	 			$.ajax({
					type:"post",
	 			url:"pay.action",
	 			data:{sum2:s,password:password},
	 			success:function(msg){
	 				if(msg=="fail1"){
	 					alert("余额不足！");
	 				}else if(msg=="fail2"){
	 					alert("密码错误");
	 				}else{
	 					alert("付款成功！");
	 					pay(orderId);
	 				}
	 			}
	 			});
	 		}
    });
        //付款
        var pay=function(orderId){
        	window.location.href="handle_fukuan?orderId="+orderId;
        };

        
        
    });
    function queren(orderId){
    	var se=confirm("是否确认收货？");
    	if (se==true)
    	  {
    	  alert("确认收货成功！");
    	  window.location.href="handle_queren?orderId="+orderId;
    	  }
    	else
    	  {
    	  alert("确认收货失败！");
    	  }
    }
    function fahuo(orderId){
    	var se=confirm("是否确认发货？");
    	if (se==true)
    	  {
    	  alert("发货成功！");
    	  window.location.href="handle_fahuo?orderId="+orderId;
    	  }
    	else
    	  {
    	  alert("发货失败！");
    	  }
    }
    </script>
    <link type="text/css" rel="stylesheet" href="css/BuyBaby.css">
    <style type="text/css">
    	a:HOVER {
			color: orangered;
		}
		 a{text-decoration: none;}
		p:HOVER {
			color: orangered;
		}
		.div1{width:280px;background-color:#D2DCA4;height:35px;border-top-right-radius:5px;border-top-left-radius:5px;}
		.div1_01{font-size :13px;line-height:35px;margin-left:20px;}
		.div2{margin-left:70px;font-size :13px;margin-top:10px;}
		.div3{margin-left:70px;margin-top:10px;}
		.hideinfo{width:280px;background-color:white;}
		input button{margin-left:20px;}
		#qurenfukuan{position: absolute;left: 355px; top:140px;width:280;height:150px;border:2px solid black;border-radius:5px;}
		::-webkit-input-placeholder{
			color: red;
		}
    </style>
</head>
<body>
    <div id="div_tz">
    <!-- 菜单栏  -->
        <ul class="navigation">
            <li class="active">所有订单</li>
            <li>买到的宝贝</li>
            <li>卖出的宝贝</li>
        </ul>
        <!-- 所有订单  -->
       
        <div class="div_content" style="padding-top: 0px;">
         <div class="div_tab" style="padding-top: 20px;">
            <table class="tab">
                <tr class="tab_tr1">
                    <th class="tab_wp">订单信息</th>
                    <th class="tab_dj">订购商品</th>
                    <th class="tab_sl">数量</th>
                    <th class="tab_danj">单价</th>
                    <th class="tab_sfk">实付款</th>
                    <th class="tab_jyzt">订单状态</th>
                    <th class="tab_cz">订单操作</th>
                </tr>
            </table>
        </div>
       		<c:choose>
				<c:when test="${orderListAll == '[]'}">
					<p class="p_kong">没有符合条件的物品，请尝试其他搜索条件!<p>
				</c:when>
				<c:otherwise>
					<c:forEach items="${orderListAll}" var="o">
					<div style="padding-top: 20px;">
						<table style=" width: 1000px;border: 1px solid #cccccc; text-align: center;
								border-collapse: separate;border-spacing: 4px 10px;font-size: 12px;">						
							<tr>
			                    <td class="tab_wp" style="text-align:left;padding-left:10px;">交易单号：${o.orderId }<br/>交易时间：${o.data }<br/>
									<c:if test="${o.buyUser.userId==user.userId}">联系卖家：${o.telephone }</c:if>
									<c:if test="${o.buyUser.userId!=user.userId}">联系买家：${o.telephone }</c:if>
			                    											</td>
			                    <td class="tab_dj" style="text-align:left;">${o.goods.goodName }</td>
			                    <td class="tab_sl">${o.count }</td>
			                    <td class="tab_danj">
			                    	<c:if test="${o.state==1&&o.buyUser.userId==user.userId}"><p style="color: red;">￥${o.price}<p></c:if>
			                    	<c:if test="${o.state==1&&o.buyUser.userId!=user.userId}"><p style="text-align: center;color: red;">￥<input id="pr" type="text" style="width: 50px;border: 0px;cursor:pointer;"  placeholder="${o.price}"/></p></c:if>
			            			<c:if test="${o.state!=1}"><p style="color: red;">￥${o.price}<p></c:if>
			                    </td>
			                    <td class="tab_sfk"><p style="color: red;">￥${o.price*o.count}<p></td>
			                    <td class="tab_jyzt">
				                   		<c:if test="${o.state==1&&o.buyUser.userId==user.userId}">待付款</c:if>
				                    	<c:if test="${o.state==2&&o.buyUser.userId==user.userId}">待发货</c:if>
				                    	<c:if test="${o.state==3&&o.buyUser.userId==user.userId}">待收货</c:if>
				                    	<c:if test="${o.state==4&&o.buyUser.userId==user.userId}">待评价</c:if>
				                    	<c:if test="${o.state==5&&o.buyUser.userId==user.userId}">交易成功</c:if>
				                    	<c:if test="${o.state==6&&o.buyUser.userId==user.userId}">待评价</c:if>
				                    	<c:if test="${o.state==7&&o.buyUser.userId==user.userId}">交易成功</c:if>
				                    	
				                    	<c:if test="${o.state==1&&o.buyUser.userId!=user.userId}">未付款</c:if>
				                    	<c:if test="${o.state==2&&o.buyUser.userId!=user.userId}">需发货</c:if>
				                    	<c:if test="${o.state==3&&o.buyUser.userId!=user.userId}">已发货</c:if>
				                    	<c:if test="${o.state==4&&o.buyUser.userId!=user.userId}">需评价</c:if>
				                    	<c:if test="${o.state==5&&o.buyUser.userId!=user.userId}">需评价</c:if>
				                    	<c:if test="${o.state==6&&o.buyUser.userId!=user.userId}">等待买家评论</c:if>
				                    	<c:if test="${o.state==7&&o.buyUser.userId!=user.userId}">交易成功</c:if>
				                    	
			                    </td>
			                    <td class="tab_cz">
			                    	<c:if test="${o.state==1&&o.buyUser.userId==user.userId}">
			                    		<a href="JavaScript:;"  class="fukuan" orderId="${o.orderId}"><img src="img/fk.jpg"/></a><br/>
						                <a href="handle_delete?orderId=${o.orderId }" id="quxiao" target="baby" style="text-decoration: none;color: black;">取消订单</a>
			                    	</c:if>
			                    	<c:if test="${o.state==2&&o.buyUser.userId==user.userId}">等待卖家发货</c:if>
			                    	<c:if test="${o.state==3&&o.buyUser.userId==user.userId}"><a href="JavaScript:;" onclick="queren('${o.orderId}')" target="baby" style="text-decoration: none;color: black;"><img src="img/qrsh.jpg"/></a></c:if>
			                    	<c:if test="${o.state==4&&o.buyUser.userId==user.userId}">
			                    	<a href="handle_pingjia?orderId=${o.orderId }" target="baby" style="text-decoration: none;color: black;"><img src="img/pj.jpg"/></a>
			                    	</c:if>
			                    	<c:if test="${o.state==5&&o.buyUser.userId==user.userId}">交易成功</c:if>
			                    	<c:if test="${o.state==6&&o.buyUser.userId==user.userId}"><a href="handle_pingjia?orderId=${o.orderId }"  target="baby" style="text-decoration: none;color: black;"><img src="img/pj.jpg"/></a></c:if>
			                    	<c:if test="${o.state==7&&o.buyUser.userId==user.userId}">交易成功</c:if>
			                    	<c:if test="${o.state==1&&o.buyUser.userId!=user.userId}"><a href="JavaScript:;" onclick="location ='handle_gengjia?orderId=${o.orderId }&price='+document.getElementById('pr').value;" target="baby" style="text-decoration: none;color: black;"><img src="img/ggjg.jpg"/></a></c:if>
			                    	<c:if test="${o.state==2&&o.buyUser.userId!=user.userId}"><a href="JavaScript:;" onclick="fahuo('${o.orderId}')"  target="baby" style="text-decoration: none;color: black;"><img src="img/fh.jpg"/></a></c:if>
			                    	<c:if test="${o.state==3&&o.buyUser.userId!=user.userId}">等待买家确认收货</c:if>
			                    	<c:if test="${o.state==4&&o.buyUser.userId!=user.userId}"><a href="handle_salepingjia?orderId=${o.orderId }" target="baby" style="text-decoration: none;color: black;"><img src="img/pj.jpg"/></a></c:if>
			                    	<c:if test="${o.state==5&&o.buyUser.userId!=user.userId}"><a href="handle_salepingjia?orderId=${o.orderId }" target="baby" style="text-decoration: none;color: black;"><img src="img/pj.jpg"/></a></c:if>
			                    	<c:if test="${o.state==6&&o.buyUser.userId!=user.userId}">等待买家评论</c:if>
			                    	<c:if test="${o.state==7&&o.buyUser.userId!=user.userId}">交易成功</c:if>
			                    	<p><a href="handle_xiangq?orderId=${o.orderId }" target="baby" style="color: red;text-decoration: none;">查看详情</a></p>
			                    </td>
			                </tr>
						</table>
					</div>
					</c:forEach>
				</c:otherwise>
			</c:choose>
        </div>
        
        <div class="div_content">
       		<iframe src="BuyBaby.jsp" name="buyBaby"></iframe>
        </div>
        
        <div class="div_content">
       		<iframe src="SaleBaby.jsp"></iframe>
        </div>

		
		<div  class="hideinfo" id="qurenfukuan" >
			<div class="div1"><div class="div1_01">我的交易    > 付款<a href="#" id="bt2" style="margin-left:145px;font-size:17px;width:35px;">x</a></div></div>
			<div class="div2">输入用户密码：</div>
			<div class="div3"><input type="password" id="pay"/><br/></div>
			<div class="div3"><input type="button" id="bt1" value="确认付款" style="width:75px;"/></div>	
		</div>
    </div>
</body>
</html>